<?php

/**
 * This is the model class for table "trade_productcomment".
 *
 * The followings are the available columns in table 'trade_productcomment':
 * @property string $productCommentId
 * @property string $content
 * @property string $createdUserId
 * @property string $createdDate
 * @property string $updatedUserId
 * @property string $updatedDate
 * @property integer $likeCount
 * @property integer $dislikeCount
 * @property string $parentId
 * @property integer $isApproved
 * @property string $productId
 * @property integer $isDeleted
 *
 * The followings are the available model relations:
 * @property HrmUser $createdUser
 * @property HrmUser $updatedUser
 * @property Product $product
 * @property ProductComment $parent
 * @property ProductComment[] $productcomments
 */
class ProductComment extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return ProductComment the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'pjm_book_comment';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('content', 'required'),
			array('productId', 'length', 'max'=>20),
			array('createdDate, updatedDate', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('productCommentId, content, createdUserId, createdDate, updatedUserId, updatedDate, likeCount, dislikeCount, parentId, isApproved, productId, isDeleted', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'createdUser' => array(self::BELONGS_TO, 'HrmUser', 'createdUserId'),
			'updatedUser' => array(self::BELONGS_TO, 'HrmUser', 'updatedUserId'),
			'product' => array(self::BELONGS_TO, 'Product', 'productId'),
			'parent' => array(self::BELONGS_TO, 'ProductComment', 'parentId'),
			'productcomments' => array(self::HAS_MANY, 'ProductComment', 'parentId'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'commentId' => 'Product Comment',
			'content' => 'Content',
//			'createdUserId' => 'Created User',
//			'createdDate' => 'Created Date',
//			'updatedUserId' => 'Updated User',
//			'updatedDate' => 'Updated Date',
//			'likeCount' => 'Like Count',
//			'dislikeCount' => 'Dislike Count',
//			'parentId' => 'Parent',
//			'isApproved' => 'Is Approved',
			'productId' => 'Product',
//			'isDeleted' => 'Is Deleted',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('commentId',$this->commentId,true);
		$criteria->compare('content',$this->content,true);
//		$criteria->compare('createdUserId',$this->createdUserId,true);
//		$criteria->compare('createdDate',$this->createdDate,true);
//		$criteria->compare('updatedUserId',$this->updatedUserId,true);
//		$criteria->compare('updatedDate',$this->updatedDate,true);
//		$criteria->compare('likeCount',$this->likeCount);
//		$criteria->compare('dislikeCount',$this->dislikeCount);
//		$criteria->compare('parentId',$this->parentId,true);
//		$criteria->compare('isApproved',$this->isApproved);
		$criteria->compare('productId',$this->productId,true);
//		$criteria->compare('isDeleted',$this->isDeleted);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}